package com.zhihuishu.treenity.controller.course;



import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.zhihuishu.micro.course.openapi.course.dto.CourseOpenDto;
import com.zhihuishu.remote.RemoteException;
import com.zhihuishu.remote.RemoteResult;
import com.zhihuishu.treenity.controller.BaseController;
import com.zhihuishu.treenity.controller.BaseController.ResultRequestAndParser;
import com.zhihuishu.treenity.log.LoggerCollectionEnum;
import com.zhihuishu.treenity.service.course.CourseService;
import com.zhihuishu.treenity.util.RequestUtil;



/***
 * @author User zhouzha
 *
 */
@Controller
@RequestMapping("/course/secondStep")
public class SecondStepController  extends BaseController{
	
	@Resource
	public CourseService   courseService;
	@ResponseBody
	@RequestMapping("")
	private ModelAndView toSecondStep(Long courseId,HttpServletRequest request) throws RemoteException {
		ModelAndView mav = new ModelAndView();
		mav.addObject("courseId", courseId);
		mav.setViewName("/course/secondStep");
		if(this.isLoginUserByCourseId(mav, courseId, request.getSession())){
			return mav;
		}
		
		return mav;
	}
	/**
	 * 第二步更新操作
	 */
	@ResponseBody
	@RequestMapping(value="/upSecondStep")
	private RemoteResult<Void> upSecondStep(final CourseOpenDto course,HttpServletRequest request,HttpServletResponse response) {
		final Long updateUser=this.getLoginUID();
		RemoteResult<Void> result = new ResultRequestAndParser<Void>("第二步修改课程概要设计",
				"treenity_secondStep_upSecondStep", "课程概要设计", "upSecondStep") {
			@Override
			public RemoteResult<Void> request(Long curUserId) throws RemoteException {
				 RemoteResult<Void> result=	courseService.updateCourseInfo(course, updateUser);
				return result;
			}
		}.get();
		return result;
	}
	/**
	 * 第二步查询
	 * @throws RemoteException 
	 */
	@ResponseBody
	@RequestMapping(value="/querySecondStep")
	private RemoteResult<CourseOpenDto> querySecondStep(@RequestParam("courseId")long courseId,HttpServletRequest request,HttpServletResponse response) throws RemoteException {
		RemoteResult<CourseOpenDto> result=new RemoteResult<CourseOpenDto>();
		CourseOpenDto courseOpenDto = courseService.loadCourse(courseId).getResult();
		result.setResult(courseOpenDto);
		result.setSuccess(true);
		return result;
			
	}
	/**
	 * log 存入的表
	 */
	@Override
	protected LoggerCollectionEnum getCollectionEnum(){
        return LoggerCollectionEnum.courseExtendPropCollection;
    }	
	
}
